//扑克牌大小
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

string getCardGreater(string& str)
{
    if (str.find("joker JOKER") != string::npos)
    {
        return "joker JOKER";
    }

    size_t dashi = str.find('-');
    string card1 = str.substr(0, dashi);
    string card2 = str.substr(dashi+1);

    int card1_cnt = count(card1.begin(), card1.end(), ' ') + 1;
    int card2_cnt = count(card2.begin(), card2.end(), ' ') + 1;

    string card1_first = card1.substr(0, card1.find(' '));
    string card2_first = card2.substr(0, card2.find(' '));
    
    if (card1_cnt == card2_cnt)
    {
        string com = "345678910JQKA2jokerJOKER";
        if (com.find(card1_first) > com.find(card2_first))
            return card1;
        else  
            return card2;
    }

    if (card1_cnt == 4)
        return card1;
    else if (card2_cnt == 4)
        return card2;
    else   
        return "ERROR";
}

int main()
{
    string str;
    while (getline(cin, str))
    {
        cout << getCardGreater(str) << endl;
    }
    return 0;
}

//HJ53 杨辉三角的变形
#include <iostream>
#include <vector>
using namespace std;

int main()
{
    int n;
    cin >> n;

    vector<int> arr(2*n+3);
    arr[2] = 1;

    for (int i = 1; i<n; ++i)
    {
        for (int j = 2*i+2; j>2; --j)
        {
            arr[j] = arr[j-2] + arr[j-1] + arr[j];
        }
    }

    bool flag = false;
    for (int i = 2; i<arr.size()-2; ++i)
    {
        if (arr[i] % 2 == 0)
        {
            flag = true;
            cout << i-1 << endl;
            break;
        }
    }

    if (!flag)
    {
        cout << -1 << endl;
    }

    return 0;
}

// shared_ptr<T>& operator=(const shared_ptr<T>& sp)
// {
//     if (_ptr != sp._ptr)
//     {
//         if (--(*_pcount) == 0)
//         {
//             delete _pcount;
//             delete _ptr;
//         }
        
//         _pcount = sp._pcount;
//         ++(*_pound);
        
//         _ptr = sp._ptr;
//     }

//     return *this;
// }